﻿@model nwrole.toolbox.sync.entity.SyncEntity

@{
    ViewBag.Title = "SchemaShow";
}

<div class="box">
<h2>Table</h2>
    <div class="form">
        <ul class="fields">
            <li class="field wide">
                @Html.LabelFor(x => x.Id)
                <div class="input">@Model.Id</div>
            </li>
            <li class="field wide">
                @Html.LabelFor(x => x.Name)
                <div class="input">@Model.Name</div>
            </li>
        </ul>
    @*Id: @Model.Id<br />
    Name: @Model.Name<br />
    Table name: @Model.SourceTableName<br />
    Sync enabled: @Model.SyncEnabled<br />
    Last sync: @Model.SyncDat<br />*@
    </div>
</div>
<h2>Columns</h2>
<table class="box">
    <tr>
        <th>Column</th>
        <th>Type</th>
        <th>Nullable</th>
        @*<th>Enabled</th>*@
    </tr>
	@{ bool even = true; }
    @foreach (var c in Model.Columns)
    {        
		<tr @((even = !even) ? "class=even" : "")>
            <td class="form">
                :@c.ColumnName
            </td>        
            <td class="form">
                @c.SourceSqlTypeName
            </td>        
            <td class="form">
                @(c.SourceSqlTypeNullableBool ? "Ja" : "Nej")
            </td>        
            @*<td>
                <a href="" onclick="return ToggleColumnSyncEnabled(this, <%=c.Id%>);"><%=c.SyncEnabledString%></a>
            </td>*@

        </tr>
    }
</table>
<a href="@Url.Action("SchemaIndex")">Back</a>

<script type="text/javascript">
    function ToggleColumnSyncEnabled(obj, colId) {
        $.get('/entity/ToggleColumnSyncEnabled', { id: colId, x: Math.random() }, function (result) {
            if (result.success) {
                if (result.newValue) {
                    $(obj).text('True');
                } else {
                    $(obj).text('False');
                }
            }
            else {
                alert(result.success);
            }
        });
        return false;
    }
</script>
